<?php
/* @var $this DefaultController */

$this->breadcrumbs = array(
    $this->module->id,
);
?>

<div class="row-fluid">
    <div class="span12">
        <!--ButtonsBar Start -->
        <div class="buttons-bar">
            <div class="clear"></div>	
            <div class="pull-left">
                <div class="pull-left">

                    <a href="<?php echo Activity::viewAllUrl() ?>" 
                       class="btn">
                        <i class="icon-eye-open"></i>
                        <?php echo Yii::t('adminuser', 'Activity') ?>
                    </a> 

                    <a href="<?php echo $this->createUrl('contact/', array('lang' => $this->lang)) ?>" class="btn">
                        <i class="icon-envelope"></i>
                        <?php echo Yii::t('contact', 'Contact') ?>
                        <?php if (Contact::getCountNew() != 0): ?>
                            <span class="inf_link"><?php echo Contact::getCountNew() ?></span>
                        <?php endif; ?>
                    </a>
                </div>
            </div>
            <div class="pull-right">
                <a href="<?php echo Option::settingUrl() ?>" class="btn">
                    <i class="icon-cog"></i>
                    <?php echo Yii::t('quanly', 'Setting') ?>
                </a>
            </div>
            <div class="clear"></div>
        </div>
        <!--ButtonsBar END -->

        <!--Statistics Box Start-->
        <div class="grid">
            <div class="grid-title">
                <div class="pull-left">
                    <?php echo Yii::t('statistic', 'Statistic') ?>
                </div>
                <div class="pull-right">
                    <a href="<?php echo StatCounter::getViewUrl() ?>" class="btn">                        
                        <?php echo Yii::t('statistic', 'View All') ?>
                    </a>
                </div>
                <div class="clear"></div>   
            </div>

            <!-- Information data -->
            <div class="information-data">
                <div class="data data-last">
                    <p class="date-title">Đang Online</p>
                    <p class="date-figures">
                        <a href="#user-online">                            
                            <?php echo StatOnline::countUserOnline() ?>
                        </a>
                    </p>
                    <p class="date-figures">
                        <?php echo date('H:i') ?>
                    </p>
                </div>
                <div class="data">
                    <p class="date-title">Hôm nay, <?php echo date('d/m') ?></p>
                    <p class="date-figures">
                        <?php echo StatCounter::today(StatCounter::TYPE_VISITORS); ?>
                    </p>
                    <p class="date-figures">
                        <?php echo StatCounter::today(); ?>
                    </p>
                </div>                

                <div class="data">
                    <p class="date-title">Tháng <?php echo date('m') ?></p>
                    <p class="date-figures">
                        <?php echo StatCounter::thisMonth(StatCounter::TYPE_VISITORS); ?>
                    </p>
                    <p class="date-figures">
                        <?php echo StatCounter::thisMonth(); ?>
                    </p>
                </div>
                <div class="data">
                    <p class="date-title">Năm <?php echo date('Y') ?></p>
                    <p class="date-figures">
                        <?php echo StatCounter::thisYear(StatCounter::TYPE_VISITORS); ?>
                    </p>
                    <p class="date-figures">
                        <?php echo StatCounter::thisYear(); ?>
                    </p>
                </div>
                <div class="data">
                    <p class="date-title">Tổng cộng</p>
                    <p class="date-figures">
                        <?php echo StatCounter::total(StatCounter::TYPE_VISITORS); ?>
                    </p>
                    <p class="date-figures">
                        <?php echo StatCounter::total(); ?>
                    </p>
                </div>
            </div>
            <div class="clear"></div>
            <!-- Information data end -->
            <div class="grid-content overflow">
                <?php $stats = StatCounter::getStat(); ?>
                <table class="chart2">
                    <thead>
                        <tr>
                            <th></th>
                            <th style="color: #FF8400">Views</th>                            
                            <th style="color: #11b0ea">Visitors</th>                            
                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach ($stats as $stat): ?>
                            <tr>
                                <th><?php echo $stat->day ?></th>
                                <td><?php echo $stat->sumViews ?></td>
                                <td><?php echo $stat->sumVisitors ?></td>
                            </tr>    
                        <?php endforeach; ?>                      
                    </tbody>
                </table>                
            </div>
        </div>
        <!--Statistics Box END-->

        <div class="grid" id="user-online">
            <div class="grid-title">
                <div class="pull-left">
                    Đang truy cập
                </div>
                <div class="clear"></div>   
            </div>            
            <div class="grid-content">
                <table class="table table-mod-2">
                    <thead>
                        <tr>
                            <th>#</th>
                            <th>Url</th>
                            <th>IP</th>
                            <th>OS</th>
                            <th>Browser</th>
                            <th>Robot</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php $onlines = StatOnline::getUserOnline(); ?>
                        <?php foreach ($onlines as $online): ?>                            
                            <tr>
                                <td><?php echo date("H:i:s", $online->session_start) ?></td>
                                <td><?php echo $online->url ?></td>
                                <td><?php echo long2ip($online->ip) ?></td>
                                <td align="center"><?php echo MyAgent::platform($online->agent); ?></td>
                                <td align="center"><?php echo MyAgent::browser($online->agent); ?></td>
                                <td align="center"><?php echo MyAgent::robot($online->agent); ?></td>
                            </tr>
                        <?php endforeach; ?>                        
                    </tbody>
                </table> 
            </div>            
        </div>

    </div>
</div>

<div class="row-fluid">
    <!--Table 2 Start-->
    <?php
//    $this->widget('DataTable', array(
//        'model' => Activity::model(),
//        'title' => Yii::t('activity', 'Recent Activity'),
//        'linkViewMore' => Activity::viewAllUrl(),
//        'fieldSearch' => 'object_name',
//        'noAction' => TRUE,
//        'noPaging' => TRUE,
//        'noSort' => TRUE,
//        'limit' => 5,
//        'htmlOptions' => array('class' => 'span6'),
//        'columns' => array(
//            'admin.username',
//            array(
//                'name' => Yii::t('activity', 'Time'),
//                'value' => 'MyUtil::timeToString($data->created_at)',
//            ),
//            array(
//                'name' => Yii::t('activity', 'Type'),
//                'value' => 'Yii::t("activity", $data->type)',
//            ),
//            array(
//                'name' => Yii::t('activity', 'Object'),
//                'value' => 'Yii::t($data->object_type, $data->object_type)',
//            ),
//            'object_name',
//        ),
//    ));
    ?>
    <?php
//    $this->widget('DataTable', array(
//        'model' => Post::model(),
//        'title' => Yii::t('post', 'Index') . ' ' . Yii::t('post', 'Post'),
//        'fieldSearch' => 'title',
//        'noAction' => TRUE,
//        'noPaging' => TRUE,
//        'noSort' => TRUE,
//        'limit' => 5,
//        'linkViewMore' => $this->createUrl("post/", array('lang' => Yii::app()->language)),
//        'htmlOptions' => array('class' => 'span6'),
//        'columns' => array(
//            'title',
//            array(
//                'name' => Yii::t('datatable', 'Create At'),
//                'value' => 'MyUtil::timeToString($data->created->created_at)',
//            ),
//            array(
//                'name' => Yii::t('datatable', 'Create By'),
//                'value' => '$data->created->admin->username',
//            ),
//        ),
//    ));
    ?>
    <!--Table 2 END-->
</div>

<script>
    $(function () {
        // CHARts        


        /* table chart */
        $("table.chart2").each(function () {
            var colors = [];
            $("table.chart2 thead th:not(:first)").each(function () {
                colors.push($(this).css("color"));
                console.log($(this));
            });
            console.log(colors);
            $(this).graphTable({
                series: 'columns', position: 'replace', width: '100%', height: '250px', colors: colors
            }, {xaxis: {tickSize: 1, },
                yaxis: {
//                    max: 100,
//                    min: 0
                }, series: {
                    points: {show: true},
                    lines: {show: true, fill: false, steps: false},
                }
            });
        });

    });
</script>
